package com.slunk.pavornocturnus;

//import java.lang.reflect.Constructor;

import com.slunk.pavornocturnus.screens.*;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen;

public class PavorNocturnusGameObject extends Game {
	protected InputMultiplexer inputMultiplexer;
	PavorNocturnusFrontPanelScreen frontScreen;
	PavorNocturnusLeftPanelScreen leftScreen;
	PavorNocturnusRightPanelScreen rightScreen;
	PavorNocturnusTopPanelScreen topScreen;
	PavorNocturnusBottomPanelScreen bottomScreen;
	
	/**
	 * This helper method uses the fully qualified name of the screen to set the game to.
	 * If the screen does not already exist, it is instantiated. Then the input
	 * 
	 * @param screenName The fully qualified name of the screen to transition to
	 */
	public void setPavorNocturnusScreen(String screenName) {
		PavorNocturnusScreenObject screenObject = null;
		if (screenName.equals(PavorNocturnusLeftPanelScreen.class.getName())) {
			if (leftScreen == null) {
				System.out.println("getLeftPanelScreen");
				leftScreen = new PavorNocturnusLeftPanelScreen(this);
			}
			screenObject = leftScreen;
    	} else if (screenName.equals(PavorNocturnusFrontPanelScreen.class.getName())) {
    		if (frontScreen == null) {
				frontScreen = new PavorNocturnusFrontPanelScreen(this);
			}
    		screenObject = frontScreen;
    	} else if (screenName.equals(PavorNocturnusRightPanelScreen.class.getName())) {
    		if (rightScreen == null) {
    			System.out.println("getRightPanelScreen");
    			rightScreen = new PavorNocturnusRightPanelScreen(this);
    		}
    		screenObject = rightScreen;
    	} else if (screenName.equals(PavorNocturnusTopPanelScreen.class.getName())) {
    		if (topScreen == null) {
    			System.out.println("getTopPanelScreen");
    			topScreen = new PavorNocturnusTopPanelScreen(this);
    		}
    		screenObject = topScreen;
    	} else if (screenName.equals(PavorNocturnusBottomPanelScreen.class.getName())) {
    		if (bottomScreen == null) {
    			System.out.println("getBottomPanelScreen");
    			bottomScreen = new PavorNocturnusBottomPanelScreen(this);
    		}
    		screenObject = bottomScreen;
    	}
		
		if (screenObject != null) {
			inputMultiplexer.clear();
			inputMultiplexer.addProcessor(screenObject);
			inputMultiplexer.addProcessor(screenObject.newHandler);
			
			this.setScreen(screenObject);
		}
	}
	
	@Override
    public void create()
    {
		//Let the game handle this. So all screens can have the input processor and not have to create a new one. It must be shared.
		inputMultiplexer = new InputMultiplexer();
		Gdx.input.setInputProcessor(inputMultiplexer);

		this.setPavorNocturnusScreen(PavorNocturnusFrontPanelScreen.class.getName());
    }

    @Override
    public void resize(int width, int height )
    {
        super.resize( width, height );
    }

    @Override
    public void render()
    {
        super.render();
    }

    @Override
    public void pause()
    {
        super.pause();
    }

    @Override
    public void resume()
    {
        super.resume();
    }
   
    @Override
    public void setScreen(Screen screen )
    {
        super.setScreen( screen );
    }
    
    @Override
    public void dispose()
    {
        super.dispose();
    }
}
